/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.hutech09.jsale.web.manager.price;

import java.io.Serializable;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.hutech09.jsale.bsn.IProductManager;
import org.hutech09.jsale.bsn.exception.ItemNotFoundException;
import org.hutech09.jsale.entity.Price;
import org.hutech09.jsale.entity.Product;

/**
 *
 * @author Nam
 */
@ManagedBean
@SessionScoped
public class PriceCuCtrl  implements Serializable{

    private Price price;

    @EJB
    private IProductManager pm;

    private String afterApplyPage;
    
    private Date test;

    public String showCreate(String afterApplyPage, Product product) {
        this.price = new Price();
        this.afterApplyPage = afterApplyPage;
        this.price.setProduct(product);
        return "priceCreatePage";
    }

    public String showUpdate(Price price, String afterApplyPage, Product product) {
        this.price = price;
        this.afterApplyPage = afterApplyPage;
        price.setProduct(product);
        return "priceUpdatePage";
    }

    public String create() {
        System.err.println(test);
        price.setApplyDateTime(test);
        System.err.println(price.getApplyDateTime());
        System.err.println(price);
        pm.addPrice(price);
        return afterApplyPage;
    }

    public String cancel() {
        return afterApplyPage;
    }

    public String update() {
        try {
            pm.updatePrice(price);
            return afterApplyPage;
        } catch (ItemNotFoundException ex) {
            Logger.getLogger(PriceCuCtrl.class.getName()).log(Level.SEVERE, null, ex);
        }
        return "";
    }

    public Price getPrice() {
        return price;
    }

    public void setPrice(Price price) {
        this.price = price;
    }

    public Date getTest() {
        return test;
    }

    public void setTest(Date test) {
        this.test = test;
    }
    
}
